package com.chaoshan.controller;

import com.chaoshan.constant.RoleConstant;
import com.chaoshan.entity.User;
import com.chaoshan.util.entity.LoginUser;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @DATE: 2022/04/28 17:49
 * @Author: 小爽帅到拖网速
 */
@RestController
public class DemoController {


    // @MyAnnotationSwagger
    @ApiOperation(value = "r1接口", notes = "测试接口r1")
    @GetMapping(value = "/r1")
    // 必须配置HttpSecurity`
    @PreAuthorize(RoleConstant.Has_ROLE_TEST_USER)
    public String r1(@RequestParam String a) {
        //获取用户身份信息
        // User userDTO = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        // return R.data(userDTO);
        User currentLoginUser = LoginUser.getCurrentLoginUser();
        return currentLoginUser.getAccountid() + "资源访问1" + a;
    }

    // @ApiOperation("r2")
    // @MyAnnotationSwagger
    @PostMapping(value = "/r2")
    @PreAuthorize(RoleConstant.HAS_ROLE_ADMIN)
    public String r2(@ApiParam(name = "用户名", value = "新增用户时提供的用户名", required = true) String a,
                     @ApiParam(name = "密码", value = "新增用户时提供的密码", required = false) String b) {
        return "r2";
    }

    @GetMapping(value = "/r3")
    @ApiOperation(value = "r3接口")
    @ApiImplicitParam(name = "m", value = "参数描述m", required = false, paramType = "query")
    public String r3(String m) {
        return m + "r3";
    }

    @GetMapping(value = "/r4")
    @ApiOperation(value = "r4接口")
    @ApiImplicitParams(
            value = {@ApiImplicitParam(name = "m", value = "参数m描述", required = false, paramType = "query"),
                    @ApiImplicitParam(name = "n", value = "参数n描述", required = true, paramType = "query")}
    )
    public String r4(@RequestParam String m, @RequestParam String n) {
        return "r4";
    }

    @PostMapping("/user")
    // @ApiImplicitParam(name = "user",paramType = "body")
    public User getUser(@RequestBody User user) {
        User user1 = new User();
        return user1;
    }
}
